import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

from sklearn.datasets import load_iris, fetch_20newsgroups
from sklearn.model_selection import train_test_split

# 读取小数据集的方法
iris = load_iris()
# print(iris)

# 读取大数据集
# news = fetch_20newsgroups()
# print(news)

print("数据集特征值：", iris.data)  # iris["data"]
print("---------------")
print("数据集目标值：", iris["target"])
print("---------------")
print("数据集特征值名字：", iris.feature_names)
print("---------------")
print("数据集目标值名字：", iris.target_names)
print("---------------")
print("数据集描述：", iris.DESCR)


# 数据可视化

# 先定义一个公共方法
def irisPlot(data, col1, col2):
    sns.lmplot(data, x=col1, y=col2, hue="target", fit_reg="False")
    plt.title("鸢尾花数据展示")
    plt.show()


iris_d = pd.DataFrame(data=iris.data,columns=["Sepal_Length", "Sepal_Width", "Petal_Length", "Petal_Width"])
iris_d["target"] = iris.target

irisPlot(iris_d,"sepal_length", "sepal_width")



x_train,x_test,y_train,y_test=train_test_split(iris.data,iris.target,test_size=0.2,random_state=22)
print("训练集特征值x_train=",x_train)
print("测试集特征值x_train=",x_test)
print("训练集目标值x_train=",y_train)
print("测试集目标值x_train=",y_test)
print("训练集目标值x_train形状",y_train.shape)
print("测试集目标值x_train形状",y_test.shape)